package com.fortune.cat.resolver;

import org.springframework.cloud.gateway.route.Route;
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

import static com.fortune.cat.enums.RateLimiterKeyResolverEnums.GLOBAL_ROUTE;

/**
 * @author zhaozeyang
 * @date 2019/4/26 10:40
 * @description 指定路由的全局限流
 */
@Component
public class GlobalKeyResolver extends AbstractKeyResolver {

    @Override
    public Integer getType() {
        return GLOBAL_ROUTE.getType();
    }

    @Override
    protected String doResolve(ServerWebExchange exchange) {
        return ((Route) exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR)).getId();
    }
}
